package com.gzy.wb.controller;

import com.gzy.wb.core.R;
import com.gzy.wb.exception.AppException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionAdvice {

    /**
     * 全局异常捕捉处理
     * @param ex
     * @return
     */
    @ResponseBody
    @ExceptionHandler(value = AppException.class)
    public R errorHandler(AppException ex) {
        R r = new R();
        r.setCode(ex.getCode());
        r.setMessage(ex.getMessage());
        return r;
    }

}


